#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int Treesum(TreeNode* root)
    {
        if (root == nullptr)
        {
            return 0;
        }
        return Treesum(root->left) + Treesum(root->right) + root->val;
    }
    void change(TreeNode* root)
    {
        if (root == nullptr)
        {
            return;
        }
        int left = Treesum(root->left);
        int right = Treesum(root->right);
        root->val = abs(left - right);
        change(root->left);
        change(root->right);
    }
    int findTilt(TreeNode* root)
    {
        change(root);
        return Treesum(root);
    }
};